package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    //根据分类id统计菜品数量
    @Select("select count(*) from sky_take_out.dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    //菜品分页(条件查询xml)
    List<DishVO> findList(DishPageDTO dishPageDTO);

    //新增菜品
    @Insert("insert into sky_take_out.dish values(null,#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill("insert")//自动填充
    @Options(useGeneratedKeys = true,keyProperty = "id")//主键返回
    void save(Dish dish);

    //主键查询
    @Select("select d.*,c.name as categoryName from sky_take_out.dish d " +
            "left join sky_take_out.category c on d.category_id = c.id where d.id = #{id}")
    DishVO findById(Long id);

    //修改菜品
    @AutoFill("update")
    void update(Dish dish);

    //主键删除
    @Delete("delete from sky_take_out.dish where id = #{id}")
    void deleteById(Long id);

}
